package cn.cloud.project.consumer.controller;

import cn.cloud.project.consumer.config.StudentConfig;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author: cql
 * @date: 2024/11/3
 * @description:
 */
@RefreshScope // 配置发布之后，动态刷新配置
@RestController
@RequestMapping("/config")
public class ConfigController {

    @Value("${user.id:1}")
    private String id;

    @Value("${user.name:zhangshan}")
    private String name;

    @Value("${user.age:10}")
    private String age;


    @Value("${student.id:1}")
    private String studentId;

    @Value("${student.name:zhangshan}")
    private String studentName;

    @Value("${student.age:10}")
    private String studentAge;

    @Value("${extend:''}")
    private String extend;

    @Value("${priority:-1}")
    private String priority;

    @Resource
    private StudentConfig studentConfig;

    @GetMapping("/test")
    public String testConfig() {
        return "(id:" + id + ",name:" + name + ",age:" + age + ")";
    }

    @GetMapping("/test/share")
    public String testShareConfig() {
        // return "(id:" + studentId + ",name:" + studentName + ",age:" + studentAge + ")";
        return studentConfig.toString();
    }

    @GetMapping("/test/extend")
    public String testExtendConfig() {
        return extend;
    }

    @GetMapping("/test/priority")
    public String testPriority() {
        return priority;
    }

}
